package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "200101",name="修改住院患者基本信息：UpdateInpPatient()")
public class UpdateInpPatientHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("channelCode");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        Assert.notNull(idNo, "idNo 不可为空！");
        // 患者ID
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        Assert.notNull(patientId, "patientId 不可为空！");
        // 姓名
        String name = requestMessage.getArgsPropertyStringValue("name");
        // 性别，中文（男、女）
        String sex = requestMessage.getArgsPropertyStringValue("sex");
        // 出生日期
        String dateOfBirth = requestMessage.getArgsPropertyStringValue("dateOfBirth");
        // 出生地
        String birthPlace = requestMessage.getArgsPropertyStringValue("birthPlace");
        // 户口地址
        String mailingAddress = requestMessage.getArgsPropertyStringValue("mailingAddress");
        // 现住址
        String currentAddress = requestMessage.getArgsPropertyStringValue("currentAddress");
        // 邮政编码
        String zipCode = requestMessage.getArgsPropertyStringValue("zipCode");
        // 籍贯
        String nativePlace = requestMessage.getArgsPropertyStringValue("nativePlace");
        // 联系电话
        String phoneNumberHome = requestMessage.getArgsPropertyStringValue("phoneNumberHome");
        // 国籍
        String citizenship = requestMessage.getArgsPropertyStringValue("citizenship");
        // 民族
        String nation = requestMessage.getArgsPropertyStringValue("nation");
        // 医保卡号
        String insurCardNo = requestMessage.getArgsPropertyStringValue("insurCardNo");
        // 工作单位
        String serviceAgency = requestMessage.getArgsPropertyStringValue("serviceAgency");
        // 联系人姓名
        String nextOfKin = requestMessage.getArgsPropertyStringValue("nextOfKin");
        // 与联系人关系
        String relationship = requestMessage.getArgsPropertyStringValue("relationship");
        // 联系人电话
        String nextOfKinPhone = requestMessage.getArgsPropertyStringValue("nextOfKinPhone");
        // 联系人地址
        String nextOfKinAddr = requestMessage.getArgsPropertyStringValue("nextOfKinAddr");
        // 联系人邮政编码
        String nextOfKinZipCode = requestMessage.getArgsPropertyStringValue("nextOfKinZipCode");
        // 婚姻状况
        String maritalStatus = requestMessage.getArgsPropertyStringValue("maritalStatus");


        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参
        Map<String, Object> res = inHosAgent.updateInpPatient(channelCode, hospitalCode, idNo, patientId, name, sex, dateOfBirth, birthPlace, mailingAddress, currentAddress, zipCode, nativePlace, phoneNumberHome, citizenship, nation, insurCardNo, serviceAgency, nextOfKin, relationship, nextOfKinPhone, nextOfKinAddr, nextOfKinZipCode, maritalStatus);

        // 设置应答信息
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
